import http from '@/common/request'
import { encrypt } from '@/common/jsencrypt'

// 登录
export function login(username, password) {
	password = encrypt(password);
	return http.request({
		url: '/login/simple',
		method: 'post',
		data: {
			username,
			password
		},
		needToken: false
	})
}



// 登出
export function logout() {
	return http.request({
		url: '/logout',
		method: 'post',
	})
}

// 获取用户详细信息
export function getUserInfo() {
  return http.request({
    url: '/getInfo',
    method: 'get',
	needToken: true
  })
}

// 获取学生详细信息
export function getStudentInfo() {
  return http.request({
    url: '/base/student/my',
    method: 'get',
	needToken: true
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return http.request({
    url: '/system/user/profile',
    method: 'get',
	needToken: true
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return http.request({
    url: '/system/user/profile',
    method: 'put',
    data: data,
	needToken: true
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  oldPassword = encrypt(oldPassword);
  newPassword = encrypt(newPassword);
  const data = {
    oldPassword,
    newPassword
  }
  return http.request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    data: data,
	header: {
	        'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
	    },
	needToken: true
  })
}


// 登录
export function selectUser() {
	return http.request({
		url: '/sys/public/user',
		method: 'get',
		needToken: true
	})
}

// 登录
export function selectDept() {
	return http.request({
		url: '/sys/public/dept',
		method: 'get',
		needToken: true
	})
}
